require(["common", "hash_routie", "coAjax", "queryString", "href", "serverNotify"], function(jSouper, hash_routie, coAjax, QueryString, href, serverNotify) {
	/*
	 * 商家信息并为其配置HASH路由
	 */
	var permission_error_vm = jSouper.parse("<h1>权限不足</h1>")(App);
	window.showLoader();
	coAjax.get(appConfig.bus.loginer, function(data) {
		window.busInfo = data.result;
		App.set("bus_loginer", busInfo);
		if (busInfo._current_employee) {
			var loginer_perms = [];
			jSouper.forEach(busInfo._current_employee.perms, function(permission_key) {
				loginer_perms.push.apply(loginer_perms, permission_key.split("|"));
			});
			App.set("$Cache.perms", loginer_perms);
		}
		hash_routie({
			html_url: "./pages/admin/",
			js_url: "./js/pages/admin/",
			hash_prefix: "admin/:page",
			default_hash: loginer_perms ? (loginer_perms.indexOf("orders") !== -1 ? "orders" : loginer_perms[0]) : "orders",
			teleporter: "right",
			before_handle: function(hash_key, _viewModules) {
				if (loginer_perms && loginer_perms.indexOf(hash_key) === -1) {
					alert("error", "权限不足")
					_viewModules[hash_key] = permission_error_vm;
				}
			}
		});
		window.removeLoader();
	}, function(errorCode, xhr, errorMsg) {
		console.log(errorCode);
		switch (errorCode) {
			case "JSON Parse Error":
				break;
			default:
				href.toBusLogin();
		}
	});
	//届时会换成"/"+busInfo._id
	App.set("base_url", "");

	var bus_notify = serverNotify("bus");
	App.set("$Cache.bus_notify", bus_notify);
	App.set("$Event.bus.loginout", function() {
		href.jump("/admin-login.html");
		coAjax.post(appConfig.bus.loginout, function() {
			alert("成功退出登录");
		});
	});

	//空间使用形式
	jSouper.registerHandle("#Space", function(space_type) {
		var res = "";
		if (space_type) {
			jSouper.forEach(appConfig.SPACE_TYPE, function(value, key) {
				if (value == space_type) {
					res = key;
				}
			})
		}
		return res;
	})
});